package com.example.peibei.ui.adapter;

import android.graphics.Color;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dingtao.common.ApplyMember;
import com.dingtao.common.bean.PaidanList2;
import com.example.peibei.R;
import com.scwang.smartrefresh.layout.util.DensityUtil;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class PaidanLists1Adapter extends BaseQuickAdapter<PaidanList2, BaseViewHolder> {
    public PaidanLists1Adapter() {
        super(R.layout.item_paidan_list1);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, PaidanList2 paidanList2) {
        baseViewHolder.setText(R.id.tv_date,paidanList2.getDate());
        baseViewHolder.setText(R.id.tv_content,paidanList2.getContent());
        baseViewHolder.setText(R.id.tv_price,paidanList2.getPrice());
        baseViewHolder.setText(R.id.tv_category,paidanList2.getCategory());
        baseViewHolder.setText(R.id.tv_start_time,paidanList2.getBeginTime());
        baseViewHolder.setGone(R.id.bottom_ll,paidanList2.getStatus()!= 0);

        LinearLayout layout = baseViewHolder.getView(R.id.image_layout);
        layout.removeAllViews();
        List<ApplyMember> applyMember = paidanList2.getApplyMember();
        if (applyMember != null && applyMember.size() > 0){
            int len = applyMember.size();
            boolean isMore = false;
            if (len > 3){
                len = 3;
                isMore = true;
            }
            for (int i = 0; i < len; i++) {
                CircleImageView image = new CircleImageView(getContext());
                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DensityUtil.dp2px(28), DensityUtil.dp2px(28));
                params.rightMargin = DensityUtil.dp2px(7);
                image.setLayoutParams(params);
                layout.addView(image);
                Glide.with(getContext()).load(applyMember.get(i).getMemberImg())
                        .error(R.mipmap.logo)
                        .placeholder(R.mipmap.logo)
                        .into(image);
            }
            if (isMore){
                TextView tv = new TextView(getContext());
                tv.setText("...");
                tv.setTextSize(20);
                tv.setTextColor(Color.BLACK);
                layout.addView(tv);
            }
        }
    }
}
